import { observable, action } from 'mobx';
import * as API_COUNT from '../apis/count';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

export class DocCountStore {
  @observable title = getLabel(132045, '阅读量统计');
  @observable loading = false;
  @observable conditions = [];
  @observable peopleNum = [];
  @observable docNum = [];
  @observable readPeopleNum = [];
  @observable reportData = [];
  @observable subdepartment = '';
  @observable department = '';
  @observable loadingChart = true;
  @observable loadingRPN = true;
  @observable loadingPN = true;
  @observable loadingDN = true;
  constructor() {
    this.setTitle = this.setTitle.bind(this);
    this.setLoading = this.setLoading.bind(this);
    this.getCondition = this.getCondition.bind(this);
    this.getPeopleNum = this.getPeopleNum.bind(this);
    this.getDocNum = this.getDocNum.bind(this);
    this.getReadPeopleNum = this.getReadPeopleNum.bind(this);
    this.getReportData = this.getReportData.bind(this);
  }

  @action
  setTitle(title) {
    this.title = title;
  }

  setLoading(loading) {
    this.loading = loading;
  }

  getCondition(params = {}) {
    API_COUNT.getCondition(params).then((data) => {
      this.conditions = data.conditions;
      this.conditions.forEach((item) => {
        item.labelcol = 3;
        item.fieldcol = 21;
      });
      this.conditions[0].options.forEach((item) => {
        if (item.key === '6') {
          this.conditions[0].selectLinkageDatas = {
            6: {
              conditionType: 'RANGEPICKER',
              domkey: ['doccreatedatefrom', 'doccreatedateto'],
            },
          };
        }
      });
      this.subdepartment = data.conditions[1].selectLinkageDatas['2']
        .browserConditionParam.replaceDatas[0].id;
      this.department = data.conditions[1].selectLinkageDatas['3']
        .browserConditionParam.replaceDatas[0].id;
    });
  }

  getPeopleNum(params = {}) {
    this.loadingChart = true;
    API_COUNT.getPeopleNum(params).then((data) => {
      this.peopleNum = data;
      this.loadingPN = false;
    });
  }

  getDocNum(params = {}) {
    this.loadingDN = true;
    API_COUNT.getDocNum(params).then((data) => {
      this.docNum = data;
      this.loadingDN = false;
    });
  }

  getReadPeopleNum(params = {}) {
    this.loadingRPN = true;
    API_COUNT.getReadPeopleNum(params).then((data) => {
      this.readPeopleNum = data;
      this.loadingRPN = false;
    });
  }

  getReportData(params = {}) {
    this.loadingChart = true;
    API_COUNT.getReportData(params).then((data) => {
      this.reportData = data;
      this.loadingChart = false;
    });
  }
}

